package com.ztesoft.sca.controller;

import com.ztesoft.sca.common.Constants;
import com.ztesoft.sca.model.ImButtonDto;
import com.ztesoft.sca.model.ScaOrderResult;
import com.ztesoft.sca.service.AudioResultService;
import com.ztesoft.sca.service.ImButtonService;
import com.ztesoft.sca.util.exception.ExceptionUtil;
import com.ztesoft.sca.util.message.ResponseUtils;
import com.ztesoft.sca.util.seq.SequenceCreator;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author: huang.xizi
 * @Date: 2018/5/30 16:50
 */

@RestController
public class AudioResultController {
	private static final Logger logger = Logger.getLogger(AudioResultController.class);

	@Autowired
    private AudioResultService audioResultService;
	

	@RequestMapping(value = "/audioResult/getResultByOrderId",method = {RequestMethod.GET})
	public String getAudioResultByOrderId(@RequestBody String requestBody,HttpServletRequest request) {
		logger.info("-------audioResult--getResultByOrderId-----");

		JSONObject qryJson = JSONObject.fromObject(requestBody);
		Long orderId=qryJson.getLong("orderId");
        ScaOrderResult scaOrderResult=null;
		try {
            scaOrderResult=this.audioResultService.getAudioResultByOrderId(orderId);
		} catch (Exception e) {
			 logger.error(" audioResult getResultByOrderId occur an error!",e);
			 return ResponseUtils.feedback(Constants.INF_CODE_ERROR,Constants.INF_DESC_ERROR, ExceptionUtil.getMessage(e));
		}

        JSONArray json = new JSONArray();
        JSONObject jo = new JSONObject();
        jo.put("orderId", scaOrderResult.getOrderId());
        jo.put("isBookStandard", scaOrderResult.isBookStandard());
        jo.put("scaBookDesc",scaOrderResult.getScaBookDesc());
        jo.put("handupStandard", scaOrderResult.isHandupStandard());
        jo.put("scaHandupDesc", scaOrderResult.getScaHandupDesc());

        json.add(jo);

		JSONObject jsonStrAll = new JSONObject();
		jsonStrAll.put("data", json);
        return ResponseUtils.feedback(Constants.INF_CODE_SUCC,Constants.INF_DESC_SUCC,jsonStrAll);	
	}
	

}
